package t10086.Model.Entity;

import jakarta.persistence.*;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;


@Entity
@Table(name = "delivery_record")
public class DeliveryRecord {
    @Id
    @Column(name = "tracking_number",nullable = false,columnDefinition = "varchar(255)")
    private  String trackingNumber;
    @Column(name = "order_number",nullable = false,columnDefinition = "varchar(255")
    private  String orderNumber;
    @Column(name = "serial_number",nullable = false,columnDefinition = "varchar(255)")
    private  String serialNumber;

    @Column(name = "delivery_date",nullable = false,columnDefinition = "date")
    private LocalDateTime deliveryDate;
    @Column(name = "consumed_time",nullable = false,columnDefinition = "int")
    private int consumedTime;
    @Column(name = "`status`",nullable = false,columnDefinition = "int")
    private int status;
    @Column(name = "`window`",nullable = false,columnDefinition = "int")
    private int window;

    public DeliveryRecord() {}
    public DeliveryRecord(Robot robot, Order order) {
        this.orderNumber = order.getOrderNumber();
        this.serialNumber = robot.getSerialNumber();
        this.trackingNumber ="DV"+System.currentTimeMillis()+UUID.randomUUID().toString().replace("-", "").substring(0, 6);
        this.deliveryDate = LocalDateTime.now();
        this.consumedTime = 0;
        this.status = 0;
        this.window = -1;
    }
    public DeliveryRecord(String serialNumber, String orderNumber) {
        this.orderNumber = orderNumber;
        this.serialNumber = serialNumber;
        this.trackingNumber ="DV"+System.currentTimeMillis()+UUID.randomUUID().toString().replace("-", "").substring(0, 6);
        this.deliveryDate = LocalDateTime.now();
        this.consumedTime = 0;
        this.status = 0;
        this.window = -1;
    }
    public Map<String,Object> toMap() {
        Map<String,Object> map = new HashMap<>();
        map.put("trackingNumber",trackingNumber);
        map.put("orderNumber",orderNumber);
        map.put("serialNumber",serialNumber);
        map.put("deliveryDate",deliveryDate);
        map.put("consumedTime",consumedTime);
        map.put("status",status);
        map.put("window",window);
        return map;
    }
    public String getTrackingNumber() { return trackingNumber; }

    public void setTrackingNumber(String trackingNumber) { this.trackingNumber = trackingNumber; }

    public String getOrderNumber() { return orderNumber; }

    public void setOrderNumber(String orderNumber) { this.orderNumber = orderNumber; }

    public String getSerialNumber() { return serialNumber; }

    public void setSerialNumber(String serialNumber) { this.serialNumber = serialNumber; }

    public LocalDateTime getDeliveryDate() {
        return deliveryDate;
    }

    public void setDeliveryDate(LocalDateTime deliveryDate) {
        this.deliveryDate = deliveryDate;
    }

    public int getConsumedTime() {
        return consumedTime;
    }

    public void setConsumedTime(int consumedTime) {
        this.consumedTime = consumedTime;
    }

    public int getStatus() {
        return status;
    }

    public int getWindow() {
        return window;
    }
    public void setWindow(int window) {
        this.window = window;
    }
    public void setStatus(int status) {
        this.status = status;
    }
    @Override
    public String toString() {
        return "DeliveryRecord:[trackingNumber=" + trackingNumber + ", orderNumber=" + orderNumber + "," +
                " serialNumber=" + serialNumber+ ", deliveryDate=" + deliveryDate + ", consumedTime="
                + consumedTime + ", status=" + status + ", window=" + window + "]";
    }
}